﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.StopZero.CApStopZeroMotionVolumeGraphicsCreator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.StopZero.Resources;
using EngineeringInternalExtension;
using EngineeringInternalExtension.DataTypes;
using System;
using System.Collections.Generic;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.StopZero;

public sealed class CApStopZeroMotionVolumeGraphicsCreator
{
  private double _timeInterval;
  private TxColor _riskZoneColor;
  private ITxGeometryCreation _resultScope;
  private List<CApStopZeroSafetyVolume> _safetyVolumes;
  private List<List<TxRobotSimulationStopMotionData>> _stopMotionData;

  public CApStopZeroMotionVolumeGraphicsCreator(
    List<CApStopZeroSafetyVolume> safetyVolumes,
    List<List<TxRobotSimulationStopMotionData>> stopMotionData,
    double timeInterval,
    TxColor color,
    ITxGeometryCreation scope)
  {
    this._safetyVolumes = safetyVolumes;
    this._stopMotionData = stopMotionData;
    this._timeInterval = timeInterval;
    this._resultScope = scope;
    this._riskZoneColor = color;
  }

  public void Create()
  {
    if (this._stopMotionData.Count == 0)
      return;
    bool flag = true;
    TxPrimitivesSetCreationDataEx safetyVolumeCreationData = new TxPrimitivesSetCreationDataEx();
    foreach (List<TxRobotSimulationStopMotionData> intervalData in this._stopMotionData)
      flag &= this.AddSphereEnities(safetyVolumeCreationData, intervalData);
    if (flag)
      return;
    this.SetSafetyVolumeAttributes(TxBaseGeometryCreationObjectEx.CreatePrimitivesSet(this._resultScope, safetyVolumeCreationData) as ITxDisplayableObject);
  }

  private static string TimeValueToString(double val)
  {
    return (val / TxApplication.Options.Units.TimeMultiplier).ToString("F" + TxApplication.Options.Units.TimeDigitsAfterDecimalPoint.ToString());
  }

  private void SetSafetyVolumeAttributes(ITxDisplayableObject safetyVolume)
  {
    safetyVolume.Color = this._riskZoneColor;
    string str = CApStopZeroMotionVolumeGraphicsCreator.TimeValueToString(this._timeInterval);
    ((ITxObject) safetyVolume).Name = string.Format(StopZeroStringTable.RiskZoneName, (object) str);
  }

  private bool AddSphereEnities(
    TxPrimitivesSetCreationDataEx safetyVolumeCreationData,
    List<TxRobotSimulationStopMotionData> intervalData)
  {
    bool isEmptyDataSet = true;
    this._safetyVolumes.ForEach<CApStopZeroSafetyVolume, TxRobotSimulationStopMotionData>((IEnumerable<TxRobotSimulationStopMotionData>) intervalData, (Action<CApStopZeroSafetyVolume, TxRobotSimulationStopMotionData>) ((safetyVolumesData, data) =>
    {
      if (data.CenterPositions.Count == 0)
        return;
      double sphereRadius = safetyVolumesData.SphereInfo.Radius;
      data.Enlargements.ForEach<double, TxTransformation>((IEnumerable<TxTransformation>) data.CenterPositions, (Action<double, TxTransformation>) ((enlargement, position) =>
      {
        double num = sphereRadius + enlargement;
        safetyVolumeCreationData.AddSphere(position.Translation, num);
      }));
      isEmptyDataSet = false;
    }));
    return isEmptyDataSet;
  }
}
